home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / renderer / html / PhpdocHTMLIndexRenderer.php < prev    next >
Encoding:
PHP Script  |  2001-02-18  |  16.3 KB  |  459 lines

  1. <?php
  2. /**
  3. * Renders Index lists.
  4. *
  5. * @version  $Id: PhpdocHTMLIndexRenderer.php,v 1.6 2001/02/18 16:29:21 uw Exp $
  6. */
  7. class PhpdocHTMLIndexRenderer extends PhpdocHTMLRenderer {
  8.  
  9.     /**
  10.     * Some container in the package list.
  11.     *
  12.     * @var  array
  13.     * @see  renderPackagelist()
  14.     */
  15.     var $packageFields = array("class", "module");
  16.  
  17.     /**
  18.     * Packagelist from the PhpdocIndexAccessor
  19.     *
  20.     * @var  array
  21.     */
  22.     var $packages = array();
  23.  
  24.     /**
  25.     * Array with classtree informations
  26.     *
  27.     * @var  array
  28.     */
  29.     var $classtree = array();
  30.  
  31.     /**
  32.     * IntegratedTemplate Object used be renderClasstree()
  33.     *
  34.     * @var  object  IntegratedTemplate
  35.     * @see  renderClasstree()
  36.     */
  37.     var $treeTpl;
  38.  
  39.     /**
  40.     * IntegratedTemplateObject used by renderModulegroup()
  41.     * 
  42.     * @var  object    IntegratedTemplate
  43.     * @see  renderModulegroup()
  44.     */
  45.     var $moduleTpl;
  46.  
  47.     /**
  48.     * Sets the xml and template root directory.
  49.     * 
  50.     * @param    string  XML file path
  51.     * @param    string  Template file path
  52.     * @param    string  Name of the application
  53.     * @param    string  Filename extension
  54.     * @see      setPath(), setTemplateRoot()
  55.     */
  56.     function PhpdocHTMLIndexRenderer($path, $templateRoot, $application, $extension = ".html") {
  57.  
  58.         $this->setPath($path);
  59.         $this->setTemplateRoot($templateRoot);
  60.         $this->application = $application;
  61.         $this->file_extension = $extension;
  62.  
  63.         $this->accessor = new PhpdocIndexAccessor;
  64.         $this->tpl = new IntegratedTemplate($this->templateRoot);
  65.         $this->fileHandler = new PhpdocFileHandler;
  66.  
  67.     } // end constructor
  68.  
  69.     /**
  70.     * Builds all index files phpdoc needs assuming that the xml files have default names
  71.     * 
  72.     * @access    public
  73.     * @see    renderElementlist(), renderPackagelist(), renderFramelementlist(), renderFramePackageSummary()
  74.     */
  75.     function generate() {
  76.  
  77.         $this->renderElementlist("elementlist.xml");
  78.         $this->renderFrameElementlist("elementlist.xml");
  79.         $this->renderPackagelist("packagelist.xml");
  80.         $this->renderFramePackageSummary("packagelist.xml");
  81.         $this->renderFrameElementlist("packagelist.xml");
  82.  
  83.     } // end function generate
  84.  
  85.     /**
  86.     * Saves the generated classtree summary to disk.
  87.     * 
  88.     * @see      renderClasstree()
  89.     * @access   public
  90.     */
  91.     function finishClasstree() {
  92.  
  93.         if (!is_object($this->treeTpl)) 
  94.             return;
  95.  
  96.         $this->treeTpl->setVariable("APPNAME", $this->application);
  97.         $this->fileHandler->createFile($this->path . "phpdoc_classtree" . $this->file_extension, $this->treeTpl->get() );
  98.         $this->treeTpl = "";
  99.  
  100.     }    // end func finishClasstree
  101.  
  102.     /**
  103.     * Adds a classtree to the classtree summary template.
  104.     * 
  105.     * @param    string  XML Classtree file
  106.     * @see      finishClasstree()
  107.     * @access   public
  108.     */
  109.     function addClasstree($xmlfile) {
  110.  
  111.         $this->accessor->loadXMLFile($this->path.$xmlfile);
  112.  
  113.         if (!is_object($this->treeTpl)) {
  114.             $this->treeTpl = new IntegratedTemplate($this->templateRoot);
  115.             $this->treeTpl->loadTemplatefile("classtree.html");
  116.         }
  117.  
  118.         $this->classtree = $this->accessor->getClasstree();
  119.         $this->treeTpl->setCurrentBlock("classtree");
  120.         $this->treeTpl->setVariable("BASECLASS", $this->classtree["baseclass"]);
  121.         $this->treeTpl->setVariable("TREE", "<ul>" . $this->buildClasstreeHTML($this->classtree["baseclass"]) . "</ul>");
  122.         $this->treeTpl->parseCurrentBlock();
  123.  
  124.         return true;
  125.     } // end func addClasstree
  126.  
  127.     function finishModulegroup() {
  128.  
  129.         if (!is_object($this->moduleTpl)) 
  130.             return;
  131.  
  132.         $this->moduleTpl->setVariable("APPNAME", $this->application);
  133.         $this->fileHandler->createFile($this->path . "phpdoc_modulegroup" . $this->file_extension, $this->moduleTpl->get() );
  134.         $this->moduleTpl = "";
  135.     } // end func finishModulegroups
  136.  
  137.     /**
  138.     * Renders a modulegroup xml file.
  139.     *
  140.     * @param    string  XML File
  141.     */    
  142.     function addModulegroup($xmlfile) {
  143.  
  144.         $this->accessor->loadXMLFile($this->path.$xmlfile);
  145.  
  146.         if (!is_object($this->moduleTpl)) {
  147.             $this->moduleTpl     = new IntegratedTemplate($this->templateRoot);
  148.             $this->moduleTpl->loadTemplateFile("modulegroup.html");
  149.         }
  150.  
  151.         $modulegroup = $this->accessor->getModulegroup();
  152.         $modules = "<ul>";
  153.  
  154.         reset($modulegroup["modules"]);
  155.         while (list($k, $module) = each($modulegroup["modules"])) 
  156.             $modules .= sprintf('<li><a href="%s">%s</a>', $this->nameToUrl($module) . $this->file_extension, $module);
  157.  
  158.         $modules .= "</ul>";
  159.  
  160.         $this->moduleTpl->setCurrentBlock("modulegroup");
  161.         $this->moduleTpl->setVariable("MODULEGROUP", $modulegroup["group"]);
  162.         $this->moduleTpl->setVariable("MODULES", $modules);
  163.         $this->moduleTpl->parseCurrentBlock();        
  164.  
  165.     } // end func addModulegroup
  166.  
  167.     /**
  168.     * Renders the element index list.
  169.     *
  170.     * @param    string  XML file
  171.     * @access   public
  172.     * @see      generate()
  173.     */ 
  174.     function renderElementlist($xmlfile) {
  175.  
  176.         $this->accessor->loadXMLFile($this->path.$xmlfile);
  177.         $this->tpl->loadTemplatefile("elementlist.html");
  178.  
  179.         $chapters = $this->accessor->getChapternames();
  180.         if (0 != count($chapters)) {
  181.  
  182.             $this->tpl->setCurrentBlock("chaptersummary_loop");
  183.  
  184.             reset($chapters);
  185.             while (list($k, $chapter) = each($chapters)) {
  186.                 $this->tpl->setVariable("CHAPTER", $chapter);
  187.                 $this->tpl->parseCurrentBlock();
  188.             }
  189.  
  190.             $chapters = $this->accessor->getChapters();
  191.             reset($chapters);
  192.             while (list($name, $elements) = each($chapters)) {
  193.  
  194.                 if (!isset($elements["element"][0])) 
  195.                     $elements["element"] = array($elements["element"]);
  196.  
  197.                 $this->tpl->setCurrentBlock("chapter_loop");
  198.  
  199.                 reset($elements["element"]);
  200.                 while (list($k, $element) = each($elements["element"])) {
  201.  
  202.                     switch($element["type"]) {
  203.                         case "package":
  204.                             $desc = "Package";
  205.                             break;
  206.  
  207.                         case "class":
  208.                             $desc = sprintf('Class <a href="%s">%s</a>.', 
  209.                                                 $this->nameToUrl($element["name"]) . $this->file_extension,
  210.                                                 $element["name"]
  211.                                             );
  212.                             break;
  213.  
  214.                         case "module":
  215.                             $desc = sprintf('Module <a href="%s">%s</a>.',
  216.                                                 $this->nameToUrl($element["name"]) . $this->file_extension,
  217.                                                 $element["name"]
  218.                                             );
  219.                             break;
  220.  
  221.                         case "functions":
  222.                             $desc = sprintf('Function in %s <a href="%s">%s</a>',
  223.                                                 $element["sourcetype"],
  224.                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
  225.                                                 $element["source"]
  226.                                             );
  227.                             break;
  228.  
  229.                         case "variables":
  230.                             $desc = sprintf('Variable in Class <a href="%s">%s</a>',
  231.                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
  232.                                                 $element["source"]
  233.                                             );
  234.                             break;
  235.  
  236.                         case "uses":
  237.                             $desc = sprintf('Included file in %s <a href="%s">%s</a>',
  238.                                                 $element["sourcetype"],
  239.                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
  240.                                                 $element["source"]
  241.                                             );
  242.                             break;
  243.  
  244.                         case "consts":
  245.                             $desc = sprintf('Constant defined in %s <a href="%s">%s</a>',
  246.                                                 $element["sourcetype"],
  247.                                                 $this->nameToUrl($element["source"]) . $this->file_extension,
  248.                                                 $element["source"]
  249.                                             );
  250.                             break;
  251.  
  252.                     }
  253.  
  254.                     $this->tpl->setVariable("ELEMENTNAME", $element["name"]);
  255.                     $this->tpl->setVariable("ELEMENT", $desc);
  256.                     $this->tpl->setVariable("SHORTDESCRIPTION", $element["value"]);
  257.                     $this->tpl->parseCurrentBlock();
  258.  
  259.                 }
  260.  
  261.                 $this->tpl->setCurrentBlock("chapter");
  262.                 $this->tpl->setVariable("CHAPTER", $name);
  263.                 $this->tpl->parseCurrentBlock();
  264.  
  265.             }
  266.  
  267.         }
  268.  
  269.         $this->tpl->setVariable("APPNAME", $this->application);
  270.         $this->fileHandler->createFile($this->path . "phpdoc_elementlist" . $this->file_extension, $this->tpl->get() );
  271.         $this->tpl->free();
  272.  
  273.     } // end func renderElementlist
  274.  
  275.     /**
  276.     * Renders a complete packagelist.
  277.     *
  278.     * @param    string  XML file
  279.     * @access   public
  280.     * @see      renderFrameElementlist(), renderFramePackagesummary()
  281.     */
  282.     function renderPackagelist($xmlfile) {
  283.  
  284.         $this->loadPackagelist($xmlfile);
  285.         $this->tpl->loadTemplatefile("packagelist.html");
  286.  
  287.         reset($this->packages);
  288.         while (list($packagename, $package) = each($this->packages)) {
  289.  
  290.             reset($this->packageFields);
  291.             while (list($k, $field) = each($this->packageFields)) {
  292.                 if (!isset($package[$field]))
  293.                     continue;
  294.  
  295.                 $this->tpl->setCurrentBlock("package_".$field."_loop");    
  296.  
  297.                 reset($package[$field]);
  298.                 while (list($k, $element) = each($package[$field])) {
  299.  
  300.                     $this->tpl->setVariable("ELEMENT", sprintf('<a href="%s">%s</a>', 
  301.                                                                     $this->nameToUrl($element) . $this->file_extension, 
  302.                                                                     $element
  303.                                                                 )
  304.                                                 );
  305.  
  306.                     $this->tpl->parseCurrentBlock();
  307.                 }
  308.  
  309.                 $this->tpl->setCurrentBlock("package_" . $field);
  310.                 $this->tpl->setVariable("EMPTY", "");
  311.                 $this->tpl->parseCurrentBlock();
  312.  
  313.             }
  314.  
  315.             $this->tpl->setCurrentBlock("package");
  316.             $this->tpl->setVariable("PACKAGE_NAME", $packagename);
  317.             $this->tpl->parseCurrentBlock();
  318.  
  319.         }
  320.  
  321.         $this->tpl->setVariable("APPNAME", $this->application);
  322.         $this->fileHandler->createFile($this->path . "phpdoc_packagelist" . $this->file_extension, $this->tpl->get() );
  323.         $this->tpl->free();
  324.  
  325.     } // end func renderPackagelist
  326.  
  327.     /**
  328.     * Renders files for the lower left frame with the elements of a certain file.
  329.     *
  330.     * @param    string  This function needs the packagelist.xml to work!
  331.     * @access   public
  332.     * @see      renderFramePackagesummary(), renderPackagelist()
  333.     */
  334.     function renderFrameElementlist($xmlfile) {
  335.  
  336.         $this->loadPackagelist($xmlfile);
  337.  
  338.         reset($this->packages);
  339.         while (list($packagename, $package) = each($this->packages)) {
  340.  
  341.             $this->tpl->loadTemplatefile("frame_packageelementlist.html");
  342.             
  343.             reset($this->packageFields);
  344.             while (list($k, $field) = each($this->packageFields)) {
  345.  
  346.                 if (!isset($package[$field]))
  347.                     continue;
  348.  
  349.                 $this->tpl->setCurrentBlock("package_" . $field . "_loop");    
  350.  
  351.                 reset($package[$field]);
  352.                 while (list($k, $element) = each($package[$field])) {
  353.  
  354.                     $this->tpl->setVariable("ELEMENT", sprintf('<a href="%s" target="main">%s</a>', 
  355.                                                                     $this->nameToUrl($element) . $this->file_extension, 
  356.                                                                     $element
  357.                                                                 ) 
  358.                                                     );
  359.                     $this->tpl->parseCurrentBlock();
  360.                 }
  361.  
  362.                 $this->tpl->setCurrentBlock("package_" . $field);
  363.                 $this->tpl->setVariable("EMPTY", "");
  364.                 $this->tpl->parseCurrentBlock();
  365.  
  366.             }
  367.  
  368.             $this->tpl->setCurrentBlock("package");
  369.             $this->tpl->setVariable("PACKAGE_NAME", $packagename);
  370.             $this->tpl->parseCurrentBlock();
  371.  
  372.             $this->tpl->setVariable("APPNAME", $this->application);
  373.             $packagename = $this->nameToUrl($packagename);
  374.             $this->fileHandler->createFile($this->path . "packageelementlist_" . $packagename . $this->file_extension, $this->tpl->get() );                    
  375.  
  376.         }
  377.  
  378.         $this->tpl->free();
  379.  
  380.     } // end func renderFrameElementlist
  381.  
  382.     /**
  383.     * Renders a Packagesummary for the frameset.
  384.     * 
  385.     * @param    string  XML file.
  386.     * @access   public
  387.     * @see      renderPackagelist(), renderFrameElementlist()
  388.     */
  389.     function renderFramePackagesummary($xmlfile) {
  390.  
  391.         $this->loadPackagelist($xmlfile);
  392.  
  393.         $this->tpl->loadTemplatefile("frame_packagelist.html");
  394.         $this->tpl->setCurrentBlock("package");
  395.  
  396.         reset($this->packages);
  397.         while (list($packagename, $v) = each($this->packages)) {
  398.  
  399.             $this->tpl->setVariable("PACKAGE", sprintf('<a href="packageelementlist_%s" target="elements">%s</a>',
  400.                                                         $this->nameToUrl($packagename) . $this->file_extension,
  401.                                                         $packagename )
  402.                                    );
  403.             $this->tpl->parseCurrentBlock();                                                            
  404.             
  405.         }
  406.  
  407.         $this->tpl->setVariable("APPNAME", $this->application);
  408.         $this->fileHandler->createFile($this->path . "frame_packagelist" . $this->file_extension, $this->tpl->get() );
  409.         $this->tpl->free();
  410.  
  411.     } // end func renderFramePackagesummary
  412.  
  413.     /**
  414.     * Imports the packagelist from the PhpdocIndexAccessor if not done previously.
  415.     * 
  416.     * @param    string      XML file.
  417.     * @see      $packages
  418.     */    
  419.     function loadPackagelist($xmlfile) {
  420.  
  421.         if (0 == count($this->packages)) {
  422.             $this->accessor->loadXMLFile($this->path . $xmlfile);
  423.             $this->packages = $this->accessor->getPackagelist();        
  424.         }
  425.  
  426.     } // end func loadPackagelist
  427.     
  428.     /**
  429.     * Recursivly builds an HTML class tree using <ul><li></ul>.
  430.     *
  431.     * @param    string  Name of the class the recursive loop starts with
  432.     * @see      renderClasstree()
  433.     */
  434.     function buildClasstreeHTML($class) {
  435.  
  436.         $html = "";
  437.         
  438.         if (0 == count($this->classtree["classes"][$class])) {
  439.  
  440.             $html .= sprintf('<li><a href="%s">%s</a>', $this->nameToUrl($class) . $this->file_extension, $class);
  441.  
  442.         } else {
  443.  
  444.             $html .= sprintf('<li><a href="%s">%s</a>', $this->nameToUrl($class) . $this->file_extension, $class);
  445.             $html .= "<ul>";
  446.  
  447.             reset($this->classtree["classes"][$class]);
  448.             while (list($k, $subclass) = each($this->classtree["classes"][$class])) 
  449.                 $html .= $this->buildClasstreeHTML($subclass);                    
  450.  
  451.             $html .= "</ul>";
  452.  
  453.         }
  454.  
  455.         return $html;
  456.     } // end func buildClasstreeHTML
  457.  
  458. } // end class PhpdocHTMLIndexRenderer
  459. ?>